import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService ,BeActionService} from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class Djjhpzlist2FrmControllerService {
  constructor(
     private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) {}

  /**
   * 按钮点击事件
   * @remarks 
   * @returns 
   */
  toolBarItemClick(): any {
      let mainName =  this.frameContext.viewModel.uiState['mainName']
      let className =  this.frameContext.viewModel.uiState['className']
      const repository = this.frameContext.repository as BefRepository<any>;
    const requestInfo = repository.restService.buildRequestInfo();
    const actionUri = 'addbl';
    const body = {
      mainName: mainName,
      className: className,
      requestInfo: requestInfo
    }
    const action$ = this.beActionService.invokeAction(actionUri, 'PUT', null, null, body);
    return action$.pipe(
      tap((responseInfo: ResponseInfo) => {})
    ) 
      debugger
  }

  /**
   * 刷新树组件
   * @remarks 
   * @returns 
   */
  reloadTree(): any {
    this.commandService.execute("LoadTree1","djpzlbTree-ycdy-component_djpzlbtree_tree-grid-component")
  }
}
